void HuffmanTree(element *huffTree, int *w, int n) {
	int i1, i2;
	for (int i = 0; i < 2 * n - 1; i++) { //初始化项目结点
		huffTree[i].parent = -1;
		huffTree[i].lchild = -1;
		huffTree[i].rchild = -1;
	}
	//初始化前n个结点的权值
	for (int i = 0; i < n; i++) {
		huffTree[i].weight = w[i];
	}
	for (int k = n; k < 2 * n - 1; k++) { //构建哈夫曼树
		select(huffTree, k, &i1, &i2);
		printf("最小下标：%d，次小下标；%d\n", i1, i2);
		huffTree[k].weight = huffTree[i1].weight + huffTree[i2].weight;//权值相加
		huffTree[i1].parent = k;//将k下标赋给即将合并的结点的双亲
		huffTree[i2].parent = k;
		huffTree[k].lchild = i1;//将合并的两个结点下标赋为k的左右孩子
		huffTree[k].rchild = i2;
	}
}
void  select(element *huffTree, int k, int *i1, int *i2) {	//寻找parent为-1的权值最小和次小的两个结点
	int index = 0, count = 0, temp;
	int arr[k];
	for (int i = 0; i < k; i++) {
		if (huffTree[i].parent == -1)
			arr[count++] = i; //将所有叶子结点的下标保存到arr中
	}
	for (int i = 0; i < count; i++) {//冒泡排序
		for (int j = 0; j < count - i - 1; j++) {
			if (huffTree[arr[j]].weight > huffTree[arr[j + 1]].weight) {
				temp = arr[j];
				arr[j] = arr[j + 1];
				arr[j + 1] = temp;
			}
		}
	}
	*i1 = arr[0];
	*i2 = arr[1];
}